# Contributor: Yves Schumann <yves@eisfair.org>
# Maintainer: Ariadne Conill <ariadne@dereferenced.org>
pkgname=quassel
pkgver=0.13.1
pkgrel=5
url="https://www.quassel-irc.org/"
pkgdesc="Distributed IRC client - metapackage"
arch="all"
license="GPL-2.0-or-later"
options="!check"
install="$pkgname-core.pre-install"
pkgusers="quassel"
pkggroups="quassel"
depends="$pkgname-mono"
depends_common=""
depends_client="$pkgname-common"
depends_mono="$pkgname-common"
depends_server="$pkgname-common qt5-qtbase-postgresql qt5-qtbase-sqlite"
depends_server_openrc=""
makedepends="cmake paxmark dbus-dev icu-dev openldap-dev openssl-dev
	qca-dev qt5-qtbase-dev qt5-qtscript-dev zlib-dev
	"
source="https://www.quassel-irc.org/pub/$pkgname-$pkgver.tar.bz2
	quasselcore.confd
	quasselcore.initd
	qt-5.14-fix.patch
	"
subpackages="$pkgname-common::noarch
	$pkgname-core:server $pkgname-core-openrc:server_openrc
	$pkgname-client $pkgname-mono
	"
builddir="$srcdir/$pkgname-$pkgver"

build() {
	cd "$builddir"
	mkdir build

	cd build
	
	CXXFLAGS="-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fPIE -pie -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now" \
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr/ \
		-DCMAKE_BUILD_TYPE="Release" \
		-DUSE_QT4=OFF \
		-DWANT_CORE=ON \
		-DWANT_MONO=ON \
		-DWANT_QTCLIENT=ON \
		-DWITH_KDE=0 \
		-DWITH_WEBKIT=OFF \
		../
	make
}

package() {
	cd "$builddir"

	make -C build DESTDIR="$pkgdir" install/fast
	paxmark -m "$pkgdir"/usr/bin/quasselcore

	install -Dm0644 "$srcdir"/quasselcore.confd \
		"$pkgdir"/etc/conf.d/quasselcore
	install -Dm0755 ${srcdir}/quasselcore.initd \
		"$pkgdir"/etc/init.d/quasselcore
}

common() {
	pkgdesc="Quassel common/shared files"
	depends="$depends_common"

	mkdir -p "$subpkgdir"/usr/share
	mv \
		"$pkgdir"/usr/share/icons \
		"$pkgdir"/usr/share/pixmaps \
		"$pkgdir"/usr/share/$pkgname \
		"$subpkgdir"/usr/share

	rmdir 2>/dev/null "$pkgdir"/usr/share/icons || :
	rmdir 2>/dev/null "$pkgdir"/usr/share/pixmaps || :
	rmdir 2>/dev/null "$pkgdir"/usr/share/$pkgname || :
	rmdir 2>/dev/null "$pkgdir"/usr/share || :
	rmdir 2>/dev/null "$pkgdir"/usr || :
}

server() {
	pkgdesc="Quassel core / server"
	depends="$depends_server"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/quasselcore "$subpkgdir"/usr/bin/
}

server_openrc() {
	pkgdesc="Quassel core / server"

	default_openrc
	rmdir 2>/dev/null "$pkgdir"/etc || :

	depends="$depends_server_openrc"
	install_if="openrc $pkgname-core=$pkgver-r$pkgrel"
}

client() {
	pkgdesc="Quassel client"
	depends="$depends_client"

	mkdir -p "$subpkgdir"/usr/bin \
		"$subpkgdir"/usr/share/applications
	mv "$pkgdir"/usr/bin/quasselclient "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/share/applications/quasselclient.desktop \
		"$subpkgdir"/usr/share/applications
}

mono() {
	pkgdesc="Quassel monolithic IRC client"
	depends="$depends_mono"

	mkdir -p "$subpkgdir"/usr/bin \
		"$subpkgdir"/usr/share/applications
	mv "$pkgdir"/usr/bin/quassel "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/share/applications/quassel.desktop \
		"$subpkgdir"/usr/share/applications

	rmdir 2>/dev/null "$pkgdir"/usr/share/applications || :
	rmdir 2>/dev/null "$pkgdir"/usr/share || :
	rmdir 2>/dev/null "$pkgdir"/usr/bin || :
	rmdir 2>/dev/null "$pkgdir"/usr || :
}

sha512sums="4ed55e81b1638c8851ddae5d9c9d23a1c2cea92f307e19f426873c2600d8e183898d3ed7c290f2ea5d1b8c5e1be7f9ffcc3e8c3c0193d080fc879b10cc3a962c  quassel-0.13.1.tar.bz2
56d4b05fcb2702c103a611a170e444e237bd7c8626219063e5853c3efa5d91e21fa9b726b056393070e35b7d7efe0a145ac3ab61413bc8033642d7acb622b638  quasselcore.confd
7a0dd5a04b28c3099b4c9e98a25e6dc2b72bdb1e450e7299f9556487f6b34748ae881a4ccb955396e2ac0eab5d3fce4dbea426d7fa498d069f5d185057efa4cf  quasselcore.initd
4be9792b0398a229102d5cef2b3931e1e9d9851ea99e647f0896c0cf9683db95ea559d7f5fb075388baea0af68cb4a30090ff95732469ecb64c439d7b8cabea0  qt-5.14-fix.patch"
